from collections import namedtuple

Stock = namedtuple('Stock', ['name', 'shares', 'price', 'date', 'time'])

# 给数据赋初始值
stock_prototype = Stock('', 0, 0.0, None, None)


def dict_to_stock(s):
    # _replace:可以进行填充修改数据
    return stock_prototype._replace(**s)


a = {'name': 'ACME', 'shares': 100, 'price': 123.45}
print(stock_prototype)

print(dict_to_stock(a))

b = {'name': 'ACME', 'shares': 100, 'price': 123.45, 'date': '12/17/2012'}
print(dict_to_stock(b))
# 可以通过它=前面的名字调用后面的值
print(dict_to_stock(b).name)
